let { AsyncSeriesWaterfallHook } = require('tapable');

class Lesson {
    constructor() {
        this.hooks = {
            arch: new AsyncSeriesWaterfallHook(['name']),
        }
    }
    tap() { // 注册监听函数
        this.hooks.arch.tapPromise('node', (name) => {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log('node', name)
                    resolve()
                }, 1000);
            })
        })
        this.hooks.arch.tapPromise('react', (name) => {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log('react', name)
                    resolve()
                }, 1000);
            })
        })
    }
    start() {
        this.hooks.arch.promise('jw').then(function () {
            // 只有两个 cb 都执行完啦 才执行这个回调函数
            console.log('end')
        })
    }
}

let l = new Lesson()

l.tap() // 注册这两个事件
l.start() // 启动钩子